import com.springboot.uav.service.UserService;
import com.springboot.uav.entity.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(classes = com.springboot.uav.TravelApplication.class)
public class UserServiceTest2 {

    @Autowired
    private UserService userService;

    @Test
    void testUpdatePhoneNumber() {

        Integer userId = 9;
        String newPhoneNumber = "15814496763";


        boolean result = userService.updatePhoneNumber(userId, newPhoneNumber);
        assertTrue(result, "更新电话号码失败！");


        String updatedPhoneNumber = userService.getPhoneNumber(userId);
        assertEquals(newPhoneNumber, updatedPhoneNumber, "电话号码更新不正确！");
    }

    @Test
    void testGetPhoneNumber() {

        Integer userId = 9;

        String expectedPhoneNumber = "15814496763";
        String actualPhoneNumber = userService.getPhoneNumber(userId);


        assertNotNull(actualPhoneNumber, "获取的手机号为空！");
        assertEquals(expectedPhoneNumber, actualPhoneNumber, "获取的手机号与预期不符！");
    }


    @Test
    void testUpdateNickname() {
        Integer userId = 9;
        String newNickname = "好汉";

        boolean result = userService.updateNickname(userId, newNickname);
        assertTrue(result, "昵称更新失败！");


        String updatedNickname = userService.getNickname(userId);
        assertEquals(newNickname, updatedNickname, "昵称更新不正确！");
    }

    @Test
    void testUpdatePassword() {
        Integer userId = 9;
        String oldPassword = "123456";
        String newPassword = "123456";


        boolean result = userService.updatePassword(userId, oldPassword, newPassword);
        assertTrue(result, "密码更新失败，可能是旧密码错误！");


        boolean isPasswordUpdated = userService.checkPassword(userId, newPassword);
        assertTrue(isPasswordUpdated, "密码更新后验证失败！");
    }
}